import config from "../config/config";
import func from "../config/func";
import AdManage from "../manage/AdManage";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import MainGame from "./MainGame";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Suspend extends cc.Component {

    @property(cc.Node)
    m_bg: cc.Node = null;

    n_mainGame: MainGame = null

    start() {
        this.n_mainGame = cc.find("Canvas/game").getComponent(MainGame);
    }

    init() {
        config.openPopup = false;
        func.setNodeAni(this.m_bg);
        if (config.gameType == "vivo") {
            func.creatrBanner();
        } else if (config.gameType == "QQ" && config.sclY < 2) {
            AdManage.instance.initQQcreateBlockAd("landscape");
        }
    }

    /**
     * 点击继续
     */
    clickContinue() {
        if (config.gameType == "vivo") {
            func.destroyBanner();
            func.creatVivoNativeAd();
        } else if (config.gameType == "QQ" && config.sclY < 2) {
            AdManage.instance.n_blockAd.destroy();
        }
        func.goReduceOut(this.m_bg, () => {
            this.node.active = false;
            this.n_mainGame.suspendGame();
        })
    }
    /**
     * 重开
     */
    clickReopen() {
        if (config.gameType == "vivo") {
            func.destroyBanner();
            func.creatVivoNativeAd();
        } else if (config.gameType == "QQ" && config.sclY < 2) {
            AdManage.instance.n_blockAd.destroy();
        }
        func.goReduceOut(this.m_bg, () => {
            this.node.active = false;
            this.n_mainGame.reopen(false);
        })
    }
    /**
     * 返回首页
     */
    clickBackToHomePage() {
        if (config.gameType == "vivo") {
            func.destroyBanner();
        } else if (config.gameType == "QQ" && config.sclY < 2) {
            AdManage.instance.n_blockAd.destroy();
        }
        func.goReduceOut(this.m_bg, () => {
            this.node.active = false;
            this.n_mainGame.backToStartScene();
        })
    }
}
